
class Company extends DateTracker implements Comparable {

    /** The type of company. */
    CompanyType type
    /** The company name. */
    String name
    /** The doctors name. */
    String doctorsName
    /** The primary address for the company. */
    Address primaryAddress
    /** The billing address, if different from primary, for the company. */
    Address billingAddress
    /** The default phone number for the company. */
    String phone
    /** The default fax number for the company. */
    String fax
    /** The default email for the company. */
    String email
    /** The website address for the company. */
    String website
    /** The list of office hours for the company. */
    OfficeHours officeHours
    /** Any notes needed for the company. */
    String notes
    /** Indicator if this company is active or not. */
    boolean active = true
    /** Indicator if this company is a principle company of the application. */
    boolean principle = false

    /** This is the parent company, if any, for this company. */
    Company parentCompany

    /**
     * These are the relational properties for the company.
     * offices: The offices for this company. If this company has multiple
     *          offices they will be here.
     * closed: This is a list of closed times for the company. For instance if
     *         the office is closed for vacation or holiday it will be listed
     *         here.
     * contact: These are the contacts of this company.
     * reps: The reps for this company. These are contacts of a principle
     *       company.
     * notifications: These are the notifications set for the company. They
     *                are for when a rep should contact a company for what ever
     *                reason.
     * officeCalls: This is the list of office calls the reps have with the
     *              company. These can be an in person walk-in, phone call,
     *              lunch, or any other office call the rep may have with a company.
     */
    static hasMany = [offices:Company, closed:OutOfOffice, contacts:Person,
        reps:Representative, notifications:Notification, officeCalls:OfficeCall]

    SortedSet offices
    SortedSet closed
    SortedSet notifications
    SortedSet officeCalls

    static constraints = {
        type(nullable:false)
        name(nullable:false, blank:false, unique:true)
        doctorsName(nullable:true, blank:true, unique:false)
        primaryAddress(nullable:false)
        billingAddress(nullable:true)
        phone(nullable:false, phoneNumber:true, blank:false)
        fax(nullable:true, phoneNumber:true)
        email(nullable:true, email:true)
        website(nullable:true)
        officeHours(nullable:true)
        notes(nullable:true, maxSize:2048)
    }

    int compareTo(obj) {
        name.compareTo(obj.name)
    }

    String toString() {
        name
    }
}
